package encrypt

import (
	"github.com/gogf/gf/v2/util/gconv"
	"math/rand"
	"strings"
)

type AesEncryptImp struct {
	token string //token
	Level uint   //加密级别
	IV    string //iv
	Key   string //key
}

func NewAesEncrypt(token string) *AesEncryptImp {
	return &AesEncryptImp{token: token}
}
func (s *AesEncryptImp) level() {
	if len(strings.TrimSpace(s.token)) == 0 {
		s.Level = 0
	} else {
		s.Level = gconv.Uint(rand.Intn(4) + 1)
	}
}
func (s *AesEncryptImp) iv() {
	switch s.Level {
	case 0:
		s.IV = "w4bmj94h8fd4aw7s"
	case 1:
		s.IV = "1a3j" + s.token[:12]
	case 2:
		s.IV = s.token[:12] + "3g5i"
	case 3:
		s.IV = "u7g4" + s.token[:12]
	case 4:
		s.IV = s.token[:12] + "w9f0"
	}
}
func (s *AesEncryptImp) key() {
	switch s.Level {
	case 0:
		s.Key = "1e5gf6ju2ytr0ec3xs7wa4df8h49jmbw"
	case 1:
		s.Key = s.token[len(s.token)-4:] + "9d7j"
	case 2:
		s.Key = "1s2w" + s.token[4:]
	case 3:
		s.Key = s.token[len(s.token)-4:] + "7f3b"
	case 4:
		s.Key = "8921" + s.token[4:]
	}
}
